
#If Not (PocketPC OrElse Smartphone) Then

Public Class silentWebBrowser
    Inherits System.Windows.Forms.WebBrowser
    Private WithEvents webBrowser2 As SHDocVw.WebBrowser

    Public Event NavigateError(ByVal disp As Object, ByRef url As Object, ByRef frame As Object _
                               , ByRef statusCode As Object, ByRef cancel As Boolean)

    Protected Overrides Sub AttachInterfaces(ByVal nativeActiveXObject As Object)
        webBrowser2 = convertor.cast(Of SHDocVw.WebBrowser)(nativeActiveXObject)
        webBrowser2.Silent = True
        MyBase.AttachInterfaces(nativeActiveXObject)
    End Sub

    Protected Overrides Sub DetachInterfaces()
        webBrowser2 = Nothing
        MyBase.DetachInterfaces()
    End Sub

    Private Sub webBrowser2_FileDownload(ByVal ActiveDocument As Boolean, ByRef Cancel As Boolean) _
                                         Handles webBrowser2.FileDownload
        Cancel = True
    End Sub

    Private Sub webBrowser2_NavigateComplete2(ByVal pDisp As Object, _
                                              ByRef URL As Object) Handles webBrowser2.NavigateComplete2
        pDisp.Document.parentWindow.execScript("function alert(){return;}" + _
                                               "function prompt(){return;}" + _
                                               "function confirm(){return;}")
    End Sub

    Private Sub webBrowser2_NavigateError(ByVal pDisp As Object, ByRef URL As Object, ByRef Frame As Object _
                                          , ByRef StatusCode As Object, ByRef Cancel As Boolean) _
                                          Handles webBrowser2.NavigateError
        RaiseEvent NavigateError(pDisp, URL, Frame, StatusCode, Cancel)
    End Sub

    Public Sub New()
        ScriptErrorsSuppressed = True
    End Sub
End Class

#End If
